import {Component, OnInit, ViewEncapsulation} from '@angular/core';
import {ImageServeService} from "@shared/service/image/image-serve.service";
import {ParentService} from "@train/parent/parent.service";
import {ActivatedRoute, Params} from "@angular/router";
import {AuthService} from "@shared/service/auth/auth.service";
import {BodyDataLatestVO} from "@interface/index";

@Component({
  selector: 'seed-grow-up-list',
  templateUrl: './grow-up-list.component.html',
  styleUrls: ['./grow-up-list.component.scss'],
  encapsulation: ViewEncapsulation.None
})
export class TrainGrowUpListComponent implements OnInit {

  public studentId: number;
  public studentName: string;
  public childBodyDataList: BodyDataLatestVO[] = [];

  constructor(
    private imageServe: ImageServeService,
    private parentService: ParentService,
    private activatedRoute: ActivatedRoute,
    private _authService: AuthService
  ) {

  }

  getIcon(name: string): string {
    return this.imageServe.getIcon(name);
  }

  /**
   * @author guoqs1331
   * @time 2018/3/29
   * @description
   */
  studentBodyDataLatest() {
    const orgUserId = this._authService.getAuthOrgId();
    this.parentService.studentBodyDataLatest(orgUserId, this.studentId).subscribe(res => {
      res.data && (this.childBodyDataList = res.data);
      if (this.childBodyDataList.length > 0) {
        this.childBodyDataList = this.childBodyDataList.filter((item) => {
          return item.bodyData && (item.bodyData.dataValue !== undefined);
        })
      }
    });
  }

  ngOnInit() {
    this.activatedRoute.params.switchMap((param: Params) => {
      this.studentId = param['studentId'];
      this.studentBodyDataLatest();
      return this.activatedRoute.queryParams
    }).subscribe((param: Params) => {
      this.studentName = param['studentName'];
    })
  }

}
